import QtQuick 2.12
import QtQuick.Controls 2.7
import QtQuick.Layouts 1.12
import Qt.labs.platform 1.1

Page {
    id: page0
    background: Rectangle{
        anchors.fill: parent
        color: "green"
    }

    footer: BaseTabBar{
        id: myBar
        height: 64
        width: parent.width
        currentIndex: swipeView0.currentIndex
        Component.onCompleted: {
            myModel.append({ "modelText": "对讲", "modelColor": "white", "modelColorG": "#000000", "modelSrc": "qrc:images/duijiang0.png", "modelSrcG": "qrc:images/duijiang1.png"})
            myModel.append({ "modelText": "广播", "modelColor": "white", "modelColorG": "#000000", "modelSrc": "qrc:/images/guangbo0.png", "modelSrcG": "qrc:/images/guangbo1.png"})
            myModel.append({ "modelText": "会议", "modelColor": "white", "modelColorG": "#000000", "modelSrc": "qrc:/images/huiyi0.png", "modelSrcG": "qrc:/images/huiyi1.png"})
            myModel.append({ "modelText": "设置", "modelColor": "white", "modelColorG": "#000000", "modelSrc": "qrc:/images/shezhi0.png", "modelSrcG": "qrc:/images/shezhi1.png"})
        }
        onCurrentIndexChanged: swipeView0.currentIndex = currentIndex
    }
    header: Rectangle {
        height: 64;
        width: parent.width;
        color: "transparent"
        id: header;
        Label {
            id: app
            text: qsTr("车间控制系统");
            font.pixelSize: 22;
            color: "white";
            anchors.left: parent.left
            anchors.verticalCenter: parent.verticalCenter
            anchors.leftMargin: 10
        }
        Button {
            id: onekeystart
            background: Item {}
            onClicked: {
                oksPopup.open();
            }
            contentItem: Text {
                text: qsTr("onekeystart");
                color: "white";
                font.pixelSize: 22;

                verticalAlignment: Text.AlignVCenter

            }

            anchors.centerIn: parent
            Onekeystart {
                id: oksPopup
                parent: Overlay.overlay
                anchors.centerIn: parent
            }

        }

        CurrentDateTime {
            //id: curtime
            anchors.right: call_btn.left
            anchors.verticalCenter: parent.verticalCenter
        }
        CallBtn {
            id: call_btn
            anchors.right: parent.right
            anchors.verticalCenter: parent.verticalCenter
            anchors.rightMargin: 10
        }

    }
    SwipeView {
        id: swipeView0
        anchors.fill: parent
        currentIndex: myBar.currentIndex
        onCurrentIndexChanged: myBar.currentIndex = currentIndex


        Rectangle{
            id: talk
            gradient: Gradient {
                GradientStop { position: 0.0; color: "#ccffe6" }
                GradientStop { position: 1.0; color: "#ccffff" }
            }

            Rectangle {
                id: talk_left
                anchors.margins: 8
                //anchors.rightMargin: 20

                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: parent.horizontalCenter

                gradient: Gradient {
                    GradientStop { position: 0.0; color: "lightsteelblue" }
                    GradientStop { position: 1.0; color: "#5EA279" }
                }
                radius: 10
                Text {
                    id: talk_recorder
                    text: "通话记录"
                    font.pixelSize: 22

                    anchors.leftMargin: 10
                    anchors.left: parent.left

                    width: 100
                    height: 30
                }

                ListView {
                    id: talk_view
                    clip: true

                    anchors.top: talk_recorder.bottom

                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.bottom: parent.verticalCenter
                    anchors.margins: 8
                    spacing: 16
                    delegate: TalkItem {
                        anchors.left: parent.left
                        anchors.right: parent.right

                        height: 48
                    }
                    Component.onCompleted: {
                        talk_view.model = Services.getTalklogModel("%", "%");
                    }
                }


                Text {
                    anchors.top: parent.verticalCenter
                    id: auth_recorder
                    text: "授权记录"
                    font.pixelSize: 22
                    anchors.leftMargin: 10
                    anchors.left: parent.left
                }

                ListView {
                    id: auth_view
                    clip: true
                    anchors.top: auth_recorder.bottom
                    anchors.margins: 8
                    anchors.left: parent.left
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right


                    spacing: 8
                    delegate: AuthItem {
                        anchors.left: parent.left
                        anchors.right: parent.right
                        height: 41
                    }
                    Component.onCompleted: {
                        auth_view.model = Services.getAuthlogModel("%", "%");

                    }
                }

            }
            Rectangle {
                id: talk_right
                radius: 10
                anchors.margins: 8
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.left: parent.horizontalCenter
                anchors.right: parent.right

                Rectangle {
                    anchors.top: parent.top
                    anchors.bottom: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.right: parent.right

                    radius: 10
                    id: warning
                    anchors.bottomMargin: 20

                    gradient: Gradient {
                        GradientStop { position: 0.0; color: "lightsteelblue" }
                        GradientStop { position: 1.0; color: "#5EA279" }
                    }
                    RowLayout {

                        id: warning_header
                        anchors.left: parent.left
                        anchors.right: parent.right
                        Image {
                            id: alarm
                            source: "qrc:images/alarm.png"
                            fillMode: Image.Stretch
                            Layout.margins: 10
                        }
                        Text {
                            id: warning_lable
                            text: qsTr("警告信息")
                            font.pixelSize: 20
                        }
                        Item {
                            Layout.fillWidth: true
                        }
                        Text {
                            text: "查看更多"
                            color: "green"
                            font.pixelSize: 16
                            Layout.rightMargin: 5
                            Layout.alignment: Qt.AlignRight
                            MouseArea {
                                id: mouseArea
                                anchors.fill: parent
                                onClicked: {
                                    stackView.push(page1)
                                    page1.tabBtnLayout.children[3].clicked_handle()
                                }

                            }
                        }


                    }

                    ListView {
                        id: warn_view
                        clip: true
                        anchors.top: warning_header.bottom


                        anchors.left: parent.left
                        anchors.right: parent.right
                        anchors.bottom: parent.bottom
                        anchors.margins: 8
                        spacing: 8
                        delegate: WarningItem {}
                        Component.onCompleted: {
                            warn_view.model = Services.getWarnlogModel("%", "%", "%");

                        }
                    }


                }
                Rectangle {
                    radius: 10
                    id: open_door
                    anchors.top: parent.verticalCenter
                    anchors.bottom: parent.bottom
                    anchors.left: parent.left
                    anchors.right: parent.right
                    gradient: Gradient {
                        GradientStop { position: 0.0; color: "lightsteelblue" }
                        GradientStop { position: 1.0; color: "#5EA279" }
                    }
                    RowLayout {
                        id: open_door_header
                        anchors.left: parent.left
                        anchors.right: parent.right
                        Image {
                            id: door
                            source: "qrc:images/door.png"
                            Layout.margins: 10
                        }
                        Text {
                            id: open_door_msg

                            text: qsTr("开门信息")
                            font.pixelSize: 20
                        }
                        Item {
                            Layout.fillWidth: true
                        }
                        Text {
                            text: "查看更多"
                            color: "green"
                            Layout.rightMargin: 5
                            Layout.alignment: Qt.AlignRight
                            font.pixelSize: 16
                            MouseArea {
                                anchors.fill: parent
                                onClicked: {
                                    console.log("show more2 clicked")
                                    stackView.push(page1)
                                    page1.tabBtnLayout.children[0].clicked_handle()
                                }

                            }
                        }


                    }
                    ListView {
                        id: open_door_view
                        clip: true
                        anchors.top: open_door_header.bottom

                        anchors.left: parent.left
                        anchors.right: parent.right
                        anchors.bottom: parent.bottom
                        anchors.margins: 8
                        spacing: 8
                        delegate: OpenDoorItem {
                            anchors.left: parent.left
                            anchors.right: parent.right
                            height: 41
                        }
                        Component.onCompleted: {
                            open_door_view.model = Services.getAuthlogModel("%", "%");

                        }
                    }
                }
            }
        }
        BroadcastView {}
        Rectangle{
            id: meeting
            Rectangle {
                width: 400
                anchors.margins: 20
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                border.color: "green"
                border.width: 2
                color: "#E8E8E8"
                ColumnLayout {
                    anchors.margins: 10
                    anchors.left: parent.left
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
                    ListView {
                        id: del_view1
                        spacing: 10
                        Layout.fillWidth: true
                        Layout.fillHeight: true

                        delegate: Rectangle {
                            width: parent.width
                            height: 48
                            RowLayout{
                                anchors.fill: parent
                                Image {
                                    id: tname
                                    source: "qrc:/images/user1.png"
                                }
                                Text {
                                    text: modelData
                                }
                                Item {
                                    Layout.fillWidth: true
                                }
                                Button {
                                    height: 48
                                    width: 48
                                    background: Item {
                                        opacity: 0
                                    }
                                    icon {
                                        source: "qrc:/images/close_face.png"
                                        //color: "white"
                                    }
                                    onClicked: {
                                        msg_dialog1.open()
                                    }
                                    Popup {
                                        id: msg_dialog1
                                        parent: Overlay.overlay
                                        height: 238
                                        width: 500
                                        padding: 0

                                        anchors.centerIn: parent
                                        background: Rectangle {

                                        }
                                        ColumnLayout {
                                            Layout.fillHeight: true
                                            width: parent.width
                                            Rectangle {
                                                height: 64
                                                Layout.fillWidth: true
                                                Text {
                                                    anchors.left: parent.left
                                                    anchors.top: parent.top
                                                    text: qsTr("移出会议")
                                                    anchors.margins: 16
                                                    font.pixelSize: 24
                                                    color: "white"
                                                }
                                                color: "green"
                                            }
                                            Rectangle {
                                                Layout.fillWidth: true
                                                height: 100
                                                Text {
                                                    text: qsTr("确定移出会议吗？")
                                                    font.pixelSize: 20
                                                    anchors.verticalCenter: parent.verticalCenter
                                                    anchors.margins: 20
                                                    anchors.left: parent.left
                                                }
                                            }

                                            RowLayout {
                                                height: 64
                                                Layout.fillWidth: true
                                                Button {
                                                    Layout.fillHeight: true
                                                    Layout.margins: 20
                                                    width: 48
                                                    text: qsTr("取消")
                                                    onClicked: {
                                                        msg_dialog1.close()
                                                    }

                                                }
                                                Item {
                                                    Layout.fillWidth: true
                                                }
                                                Button {
                                                    text: qsTr("确定")
                                                    Layout.margins: 20
                                                    onClicked: {
                                                        del_model.remove(index)
                                                        msg_dialog1.close()
                                                    }

                                                }
                                            }


                                        }

                                    }
                                }
                            }
                        }
                        Component.onCompleted: {
                                var lmodel = Services.getTeams();
                                var i;
                                for(i=0; i<lmodel.length; i++) {
                                    del_model.append({id: lmodel[i]});
                                }

                        }
                        model: ListModel {
                            id: del_model
                        }
                    }
                    Button {
                        visible: false

                        background: Rectangle{
                            color: "green"
                        }

                        contentItem: Text{
                            text: "添加"
                            font.pixelSize: 32
                        }
                        Layout.alignment: Qt.AlignBottom | Qt.AlignHCenter;
                        Layout.margins: 20
                    }
                }

            }
        }
        Rectangle{
            id: setting

            color: "#f2f2f2"
            Flow {
                anchors.fill: parent
                anchors.margins: 32
                spacing: 32
                Button {
                    implicitHeight: 300
                    implicitWidth: 150
                    text: qsTr("用户管理")
                    icon {
                        height: 64
                        width: 64
                        source: "qrc:/images/icon_11.png"
                        color: "green"
                    }
                    display: AbstractButton.TextUnderIcon
                    background: Rectangle {
                        border.width: 1
                        border.color: "#eeeeee"
                    }
                    onClicked: {
                        page0.StackView.view.push(page2)
                        //console.log("page0.StackView.view: " + page0.StackView.view)
                    }

                }

                Button {
                    implicitHeight: 300
                    implicitWidth: 150

                    text: qsTr("日志查看")
                    icon {
                        height: 64
                        width: 64
                        source: "qrc:/images/icon_22.png"
                        color: "green"
                    }
                    display: AbstractButton.TextUnderIcon
                    background: Rectangle {
                        border.width: 1
                        border.color: "#eeeeee"
                    }
                    onClicked: {
                        stackView.push(page1)
                        page1.tabBtnLayout.children[0].clicked_handle()
                    }

                }
                Button {
                    implicitHeight: 300
                    implicitWidth: 150

                    text: qsTr("广播设置")
                    icon {
                        height: 64
                        width: 64
                        source: "qrc:/images/icon_33.png"
                        color: "green"
                    }
                    display: AbstractButton.TextUnderIcon
                    background: Rectangle {
                        border.width: 1
                        border.color: "#eeeeee"
                    }
                    onClicked: {
                        stackView.push(page3)
                    }

                }
                Button {
                    implicitHeight: 300
                    implicitWidth: 150

                    text: qsTr("系统设置")
                    icon {
                        height: 64
                        width: 64
                        source: "qrc:/images/icon_44.png"
                        color: "green"
                    }
                    display: AbstractButton.TextUnderIcon
                    background: Rectangle {
                        border.width: 1
                        border.color: "#eeeeee"
                    }
                    onClicked: {
                        stackView.push(page4)
                    }

                }

            }


        }

    }

    Page2 {
        id: page2
    }
    Page3 {
        id: page3
    }
    Page4 {
        id: page4
    }

}
